#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<list>
using namespace std;
const int INF = 0x3f3f3f3f;
#define LL long long int
long long  gcd(long long  a, long long  b) { return a == 0 ? b : gcd(b % a, a); }
  
const int N = 200005;
LL a[N];                   
LL  lazy[N << 2];        
int n, q;
struct Tree
{
    int l, r;
    LL sum;
    int mid()
    {
        return (l + r) >> 1;
    }
}tree[N<<2];     
  
void PushUp(int rt)
{
    tree[rt].sum = tree[rt << 1].sum + tree[rt << 1 | 1].sum;
}
  
void PushDown(int rt,int m)
{
    if (lazy[rt])
    {
        lazy[rt << 1] += lazy[rt];
        lazy[rt << 1 | 1] += lazy[rt];
        tree[rt << 1].sum += lazy[rt] * (m - (m >> 1));
        tree[rt << 1 | 1].sum += lazy[rt] * (m >> 1);
        lazy[rt] = 0;
    }
}
  
void build(int l, int r, int rt)
{
    tree[rt].l = l;
    tree[rt].r = r;
    lazy[rt] = 0;
    if (l == r)
    {
        tree[rt].sum = a[l];
        return;
    }
    int m = tree[rt].mid();
    build(l, m, (rt << 1));
    build(m + 1, r, (rt << 1 | 1));
    PushUp(rt);
}
  
void update(LL c, int l, int r, int rt)
{
    if (tree[rt].l == l&&tree[rt].r==r)
    {
        lazy[rt] += c;
        tree[rt].sum += c*(r - l + 1);
        return;
    }
    if (tree[rt].l == tree[rt].r)return;
    int m = tree[rt].mid();
    PushDown(rt, tree[rt].r - tree[rt].l + 1);
    if (r <= m)update(c, l, r, rt << 1);
    else if (l > m)update(c, l, r, rt << 1 | 1);
    else
    {
        update(c, l, m, rt << 1);
        update(c, m + 1, r, rt << 1 | 1);
    }
    PushUp(rt);
}
  
LL Query(int l, int r, int rt)
{
    if (l == tree[rt].l&&r == tree[rt].r)
    {
        return tree[rt].sum;
    }
    int m = tree[rt].mid();
    PushDown(rt, tree[rt].r - tree[rt].l + 1);
    LL res = 0;
    if (r <= m)res += Query(l, r, rt << 1);
    else if (l > m)res += Query(l, r, rt << 1 | 1);
    else
    {
        res += Query(l, m, rt << 1);
        res += Query(m + 1, r, rt << 1 | 1);
    }
    return res;
}
 int bb[300000];
int main()
{
        cin>>n>>q;
        build(1, n, 1);
        int aa, b;
        LL c=1;
        while (q--)
        {
            cin>>aa>>b;
            update(c, aa, b, 1);
        }
        for(int i=1;i<=n;i++)
        {
            bb[i]=Query(i, i, 1);
        }
        sort(bb+1,bb+n+1);
            long long s=0;
    for(int i=n;i>=1;i--){
        s+=i*bb[i];
    }
    cout<<s<<endl;
}
